home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / 3dvect39 / irq.asm < prev    next >
Encoding:
Assembly Source File  |  1994-10-30  |  7.6 KB  |  281 lines

  1. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2. ;
  3. ; Filename     : Irq.asm
  4. ; Included from: Main Assembley Module
  5. ; Description  : Irq handler for timing/tracking vertical retrace
  6. ;
  7. ; Written by: John McCarthy
  8. ;             1316 Redwood Lane
  9. ;             Pickering, Ontario.
  10. ;             Canada, Earth, Milky Way (for those out-of-towners)
  11. ;             L1X 1C5
  12. ;
  13. ; Internet/Usenet:  BRIAN.MCCARTHY@CANREM.COM
  14. ;         Fidonet:  Brian McCarthy 1:229/15
  15. ;   RIME/Relaynet: ->CRS
  16. ;
  17. ; Home phone, (905) 831-1944, don't call at 2 am eh!
  18. ;
  19. ; John Mccarthy would really love to work for a company programming Robots
  20. ; or doing some high intensive CPU work.  Hint. Hint.
  21. ;
  22. ; Send me your protected mode source code!
  23. ; Send me your Objects!
  24. ; But most of all, Send me a postcard!!!!
  25. ;
  26. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  27.  
  28.          .386p
  29.          jumps
  30.  
  31.          include pmode.ext
  32.          include macros.inc
  33.  
  34.          public _irq_setpmirq
  35.          public _irq_resetpmirq
  36.          public _irq_resetrastercount
  37.          public _irq_timeraster
  38.          public _irq_set_timer
  39.          public _irq_reset_timer
  40.          public _irq_findcontrol
  41.  
  42.          public _irq_tracespast
  43.          public _irq_framenumber
  44.  
  45.          public _irqcontrol
  46.  
  47.          input_1 equ 03dah                  ; input status #1 register
  48.  
  49.          pmodeirq equ 0                     ; you could also use irq 8
  50.  
  51. number_of_irq_subroutines equ 8
  52.  
  53.          .386p
  54.          jumps
  55.  
  56. code32   segment para public use32
  57.          assume cs:code32, ds:code32
  58.  
  59. _irq_tracespast  dd 0                       ; contains frame speed (irq driven)
  60. _irq_framenumber dd 0                       ; number of frames total,eg 23400 = 13 mins
  61. rmirqbuf   db 21 dup(?)                     ; buffer for rm IRQ callback code
  62. ormirqvect dd 0
  63.  
  64. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  65. ; Protected mode IRQ handler
  66. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  67.  
  68. pmirq0:                                     ; protected mode IRQ0 handler
  69.          push eax
  70.          mov al,20h
  71.          out 20h,al
  72.          sti
  73.          cld
  74.          push ebx ecx edx esi edi ebp ds
  75.          mov ds, [cs:_seldata]
  76.  
  77. ; put your protected mode irq code here!!!!!
  78. ;-------------------------------------------
  79.  
  80.  
  81.  
  82. ;-------------------------------------------
  83.  
  84. ; now my code, this is where I inc that variable
  85. ; protected mode version is easy!
  86.  
  87.          inc _irq_tracespast
  88.          inc _irq_framenumber
  89.  
  90.          i = 0
  91.          rept number_of_irq_subroutines
  92.          call [d _irqcontrol+i*4]           ; call selected IRQ subroutines
  93.          i=i+1
  94.          endm
  95.  
  96.          pop ds ebp edi esi edx ecx ebx eax
  97.          iretd
  98.  
  99. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  100. ; _irq_setpmirq: Get protected mode IRQ going
  101. ; In=Out=Null
  102. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  103.  
  104. _irq_setpmirq:
  105.          pushad
  106.          mov ax,900h
  107.          int 31h
  108.          push ax
  109.  
  110.          mov bl,pmodeirq
  111.          mov edx,offset pmirq0
  112.          call _setirqvect
  113.          xor al,al
  114.          call _setirqmask
  115.          mov edi,offset rmirqbuf
  116.          call _rmpmirqset
  117.          mov ormirqvect,eax
  118.  
  119.          call _irq_timeraster
  120.          call _irq_set_timer
  121.  
  122.          pop ax
  123.          int 31h
  124.          popad
  125.          ret
  126.  
  127. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  128. ; _irq_resetpmirq: Unhook protected mode IRQ and reset original timer
  129. ; In=Out=Null
  130. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  131.  
  132. _irq_resetpmirq:
  133.          mov ax, 900h
  134.          int 31h
  135.          push ax
  136.  
  137.          mov bl,pmodeirq
  138.          mov eax,ormirqvect
  139.          call _rmpmirqfree
  140.  
  141.          mov al,1
  142.          call _setirqmask
  143.  
  144.          pop ax
  145.          int 31h
  146.  
  147.          jmp _irq_reset_timer
  148.  
  149. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  150. ; Set Irq speed
  151. ; In:
  152. ;  AX = 1193180/# interrupts per second
  153. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  154.  
  155. _irq_set_timer:
  156.          push ax
  157.          mov al,36h
  158.          out 43h,al
  159.          pop ax
  160.          out 40h,al
  161.          mov al,ah
  162.          out 40h,al
  163.  
  164.          ret
  165.  
  166. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  167. ; Reset Irq speed to default speed
  168. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  169.  
  170. _irq_reset_timer:                           ; reset timer for exit
  171.          mov al,36h
  172.          out 43h,al
  173.  
  174.          mov ax,0
  175.          out 40h,al
  176.          out 40h,al
  177.          ret
  178.  
  179. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  180. ; _irq_resetrastercount: reset counters (done before anmation loop)
  181. ; In=Out=Null
  182. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  183.  
  184. _irq_resetrastercount:                      ; reset count before any animation loop
  185.          mov _irq_tracespast,1
  186.          mov _irq_framenumber,0
  187.          ret
  188.  
  189. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  190. ; _irq_timeraster: Guess what this does?
  191. ; In=Null
  192. ; Out:
  193. ;   AX=time for raster to occure
  194. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  195.  
  196. _irq_timeraster:
  197.          pushad
  198.  
  199.          mov ax, 900h
  200.          int 31h
  201.          push ax
  202.  
  203.          mov dx, input_1                    ; input# 1 reg
  204. loop1:
  205.          in al,dx                           ; wait for vsync
  206.          test al,8
  207.          jnz loop1
  208. loop2:
  209.          in al,dx
  210.          test al,8
  211.          jz loop2
  212.  
  213.          mov al,36h                         ; reset timer
  214.          out 43h,al
  215.          mov al,0
  216.          out 40h,al
  217.          mov al,0
  218.          out 40h,al
  219. loop3:
  220.          in al,dx                           ; wait for vsync
  221.          test al,8
  222.          jnz loop3
  223. loop4:
  224.          in al,dx
  225.          test al,8
  226.          jz loop4
  227.  
  228.          xor al,al                          ; this calculation code courtesy future_crew
  229.          out 43h,al                         ; from mental.exe
  230.          in al,40h
  231.          mov ah,al
  232.          in al,40h
  233.          xchg al,ah
  234.          neg ax
  235.          shr ax,1
  236.          movzx eax,ax
  237.          mov [esp+30],ax
  238.  
  239.          pop ax
  240.          int 31h
  241.  
  242.          popad
  243.          ret
  244.  
  245. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  246. ; Find next available control vector
  247. ; Out:
  248. ;  CF - 1 no control availeble
  249. ;    ECX = ?
  250. ;  CF - 0 control available
  251. ;    ECX = next usable jump number. eg  _irqcontrol[ecx*4] (0,1,2,3...)
  252. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  253.  
  254. _irq_findcontrol:
  255.          push eax edi
  256.          mov ecx,number_of_irq_subroutines
  257.          mov edi,offset _irqcontrol
  258.          mov eax,offset _ret
  259.          repnz scasd
  260.          neg ecx
  261.          sub ecx,-number_of_irq_subroutines+1
  262.          pop edi eax
  263.          ret
  264.  
  265. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  266. ; These are the user difinable IRQ controlled jump vectors:
  267. ;
  268. ; You can have a certine function performed every  vertical retrace just
  269. ; by setting these to point to the code you wish to  be   called.   When
  270. ; you want to disable the subroutine, just reset these vectors to offset
  271. ; _ret.
  272. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  273.  
  274. _irqcontrol:
  275.          rept number_of_irq_subroutines
  276.          dd offset _ret
  277.          endm
  278.  
  279. code32   ends
  280.          end
  281.